package com.comut.crud.bo;

import com.comut.crud.dao.VehicleDao;
import com.comut.crud.ejb.interfaces.IVehicleAction;
import com.comut.crud.pojo.mobile.VehicleDetail;
import com.comut.crud.pojo.mobile.VehicleInfo;
import com.comut.lib.connection.MongoDBConnectionManager;
import java.sql.Connection;
import java.util.logging.Logger;

/**
 * Issue: IFL-1566
 *
 * @author Paulo Fournier
 */
public class VehicleHandler implements IVehicleAction {

    private static Logger _logger = Logger.getLogger(VehicleHandler.class.getName());
    private Connection _connection;
    private VehicleDao _vehicleDao;
    private final MongoDBConnectionManager _mongodb;

    /**
	 * Creates vehicle handler that uses an implementation of Connection and MongoDB
     * Issue: IFL-1566
     * @param connection
     * @param mongodb 
     */
    public VehicleHandler(Connection connection, MongoDBConnectionManager mongodb) {
        this._connection = connection;
        this._mongodb = mongodb;
        this._vehicleDao = new VehicleDao(_connection, _mongodb);
    }

    /**
     * Get the list of vehicles that belong to a user
     * @param userId The user id
     * @return VehicleInfo[] The list of vehicles
     */
    @Override
    public VehicleInfo[] getVehiclesForUserId(int userId) {
        return this._vehicleDao.getVehiclesForUserId(userId);
    }

    /**
     * Issue: IFL-1567
	 * Get the vehicle detailed information
     * @param userId The user id
     * @param vehicleId The vehicle id
     * @return 
     */
    public VehicleDetail getVehicleDetail(int userId, int vehicleId) {
        return this._vehicleDao.getVehicleDetail(userId,vehicleId);
    }
}
